/*
 * Created by JFormDesigner on Wed May 07 09:21:56 CST 2025
 */

package com.soft.bams.server;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

/**
 * @author 21603
 */
public class ServerPanel extends JPanel {
    private ATMServer atmServer;

    public ServerPanel(ATMServer atmServer) {
        this.atmServer = atmServer;
        initComponents();
    }

    private void openService(ActionEvent e) {
        atmServer.startServer(8888);
    }

    private void closeService(ActionEvent e) {
        int i = JOptionPane.showConfirmDialog(this, "确认关闭服务吗？");
        if (i == JOptionPane.YES_OPTION) {
            atmServer.stopServer();
            System.exit(0);
        }
    }

    private void openGod(ActionEvent e) {
        CardLayout cardLayout  = (CardLayout) this.getParent().getLayout();
        cardLayout.show(this.getParent(),"rank");
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents  @formatter:off
        titleLabel = new JLabel();
        openServiceButton = new JButton();
        closeServiceButton = new JButton();
        openGodButton = new JButton();

        //======== this ========
        setLayout(null);

        //---- titleLabel ----
        titleLabel.setText("ATM  \u670d\u52a1\u5668");
        titleLabel.setFont(new Font("Microsoft YaHei UI", Font.BOLD, 20));
        add(titleLabel);
        titleLabel.setBounds(new Rectangle(new Point(335, 60), titleLabel.getPreferredSize()));

        //---- openServiceButton ----
        openServiceButton.setText("\u5f00\u542f\u670d\u52a1");
        openServiceButton.addActionListener(e -> openService(e));
        add(openServiceButton);
        openServiceButton.setBounds(195, 190, 155, 55);

        //---- closeServiceButton ----
        closeServiceButton.setText("\u5173\u95ed\u670d\u52a1");
        closeServiceButton.addActionListener(e -> closeService(e));
        add(closeServiceButton);
        closeServiceButton.setBounds(445, 190, 155, 55);

        //---- openGodButton ----
        openGodButton.setText("\u5f00\u542f\u4e0a\u5e1d\u89c6\u89d2");
        openGodButton.addActionListener(e -> openGod(e));
        add(openGodButton);
        openGodButton.setBounds(320, 335, 155, 55);

        setPreferredSize(new Dimension(800, 595));
        // JFormDesigner - End of component initialization  //GEN-END:initComponents  @formatter:on
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables  @formatter:off
    private JLabel titleLabel;
    private JButton openServiceButton;
    private JButton closeServiceButton;
    private JButton openGodButton;
    // JFormDesigner - End of variables declaration  //GEN-END:variables  @formatter:on
}
